<template>
	<view class="page" style="position: relative;height: 100vh;">

		<view class="container" style="padding: 24rpx;box-sizing: border-box;background-color: ##F9FAFB;">
			
			<view class="flex-row-between"
				style="border-radius: 8rpx;background-color: #FFFFFF;margin-bottom: 32rpx;height: 168rpx;width: 100%;padding: 32rpx;box-sizing: border-box;">
				<view class="flex-colum-start" style="height: 100%;">
					<text style="color: #6B7280;font-size: 28rpx;">活动名称</text>
					<text style="font-size: 36rpx;">双十一返现活动</text>
				</view>
				<view class="">
					<text style="color:#EF4444;font-size: 28rpx;">最高返现 88%</text>
				</view>
			</view>

			<view
				style="margin-bottom: 24rpx;border-radius: 8rpx;height: 242rpx;background: #FEFCE8;;width: 100%;display: flex;flex-direction: column;justify-content: space-evenly;align-items: flex-start;padding: 16rpx;box-sizing: border-box;">
				<view class="" style="display: flex;justify-content: center;align-items: center;">
					<image src="../../static/img/mine/deng.jpg" style="width: 21rpx;height: 28rpx"></image>
					<text style="margin-left: 12rpx;color: #854D0E;font-size: 28rpx;font-weight: bold;">重要说明</text>
				</view>
				<text style="color: #A16207;font-size: 28rpx;">1. 请务必填写正确的订单号，24小时内可修改</text>
				<text style="color: #A16207;font-size: 28rpx;">2. 返现金额将在 24 小时内到账</text>
				<text style="color: #A16207;font-size: 28rpx;">3. 请确保上传清晰的订单截图 </text>

			</view>


			<view
				style="margin-bottom: 32rpx;width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
				<text style="font-size: 28rpx;color: #374151;margin-bottom: 6rpx;">订单号</text>
				<input v-model="order_no" type="text"
					style="padding: 0 32rpx;border-radius: 8rpx;width: 100%;height: 92rpx;border: 2rpx solid #F9FAFB;box-sizing: border-box;background-color: #F9FAFB;"
					placeholder-style="font-size:28rpx;color:#9CA3AF;" placeholder="请输入订单号">
			</view>


			<view
				style="margin-bottom: 32rpx;width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
				<text style="font-size: 28rpx;color: #374151;margin-bottom: 6rpx;">金额</text>
				<input v-model="total_amount" type="text"
					style="padding: 0 32rpx;border-radius: 8rpx;width: 100%;height: 92rpx;box-sizing: border-box;border: 2rpx solid #F9FAFB;background-color: #F9FAFB;"
					placeholder-style="font-size:28rpx;color:#9CA3AF;" placeholder="请输入订单金额">
			</view>


			<view
				style="margin-bottom: 32rpx;width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
				<text style="font-size: 28rpx;color: #374151;margin-bottom: 6rpx;">备注（选填）</text>
				<textarea v-model="remark" name=""
					style="padding:32rpx;border-radius: 8rpx;width: 100%;height: 192rpx;border: 2rpx solid #F9FAFB;box-sizing: border-box;background-color: #F9FAFB;"
					placeholder-style="font-size:28rpx;color:#9CA3AF;" placeholder="请输入备注信息" id="" cols="30"
					rows="10"></textarea>
			</view>

			<view v-if="has_order_stage"
				style="margin-bottom: 60rpx;width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
				<text style="font-size: 28rpx;color: #374151;margin-bottom: 6rpx;">上传下单截图</text>
				<uploadImg :initImgs="order_data_url" imageType="commission" limit="1" @uploadSuccess="uploadBigSuccess1"></uploadImg>
			</view>


			<view v-if="has_receive_stage"
				style="margin-bottom: 60rpx;width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
				<text style="font-size: 28rpx;color: #374151;margin-bottom: 6rpx;">上传收货订单截图</text>
				<uploadImg :initImgs="receive_data_url" imageType="commission" limit="1" @uploadSuccess="uploadBigSuccess2"></uploadImg>
			</view>


			<view v-if="has_comment_stage"
				style="margin-bottom: 60rpx;width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
				<text style="font-size: 28rpx;color: #374151;margin-bottom: 6rpx;">上传评价订单截图</text>
				<uploadImg :initImgs="comment_data_url" imageType="commission" limit="1" @uploadSuccess="uploadBigSuccess3"></uploadImg>
			</view>
			
			
			<view class=""
				style="border-radius: 8rpx;width: 100%;height: 96rpx;border: 1px solid #FF4D4F;line-height: 96rpx;display: flex;justify-content: center;align-items: center;color:#FF4D4F ;"
				@click="save">
				提交表单
			</view>
		</view>
	
	

	</view>
</template>
<!-- 
 has_comment_stage: true
 has_order_stage: true
 has_receive_stage: true
 id: "sc_kz87xy72zp52d5"
 name: "订单+收货+评论"
 -->
<script>
	import uploadImg from "../../components/zhtx-uploadImg/zhtx-uploadImg.vue"

	export default {
		components: {
			uploadImg
		},
		data() {
			return {
				id:"",
				product_id: "",
				statgeId: "",
				total_amount: "",
				order_no: "",
				remark: "",
				order_data:"", //下单阶段截图信息
				receive_data:"", //收货阶段截图信息
				comment_data:"",
				order_data_url: [], //下单阶段截图信息
				receive_data_url: [], //收货阶段截图信息
				comment_data_url: [], //评价阶段截图信息
				
				has_order_stage: true,
				has_receive_stage: true,
				has_comment_stage:true
				
			};
		},
		onLoad(e) {
			console.log({...e})
			this.statgeId = e.statgeId;
			this.product_id  = e.product_id;
			this.id = e.id;
			this.getSubmitStageConfig()
			
			if(this.id){
				this.getDetailById(this.id)
			}
		},
		methods: {
			getDetailById(id){
				var that = this;
				this.$pin.request('GET', `/commission/${id}`, null, successData => {
					console.log(successData)
					if (successData.code == this.$pin.code.success) {
						var result =  successData.data;
						
						that.order_no = result.order_no;
						that.total_amount = result.total_amount;
						that.remark = result.remark;
						
						that.order_data_url = [result.order_data[0].url]; //下单阶段截图信息
						that.receive_data_url = [result.receive_data[0].url]; //收货阶段截图信息
						that.comment_data_url = [result.comment_data[0].url]; //评价阶段截图信息
						
						that.order_data = result.order_data[0].id; //下单阶段截图信息
						that.receive_data=result.receive_data[0].id; //收货阶段截图信息
						that.comment_data= result.comment_data[0].id; //评价阶段截图信息
					
					} else {
			
					}
				}, failData => {
					console.log(failData)
				})
			},
			// 完成
			save() {
				if(!this.comment_data||!this.receive_data||!this.order_data){
					uni.showToast({
						title:"图片不能为空",
						icon:"error"
					})
					return;
				}
			
				var data = {
					product_id: this.product_id,
					total_amount: this.total_amount, 
					order_no: this.order_no, 
					remark: this.remark, 
					comment_data:[{
						id:this.comment_data
					}],
					receive_data:[{
						id:this.receive_data
					}],
					order_data:[{
						id:this.order_data
					}]
				};
			
				var url = `/commission`
				var requestType = 'POST'
				if(this.id){
					url += `/${this.id}`
					requestType = 'PUT'
				}
				this.$pin.request(requestType, url, data, successData => {
					console.log(successData)
					if (successData.code == this.$pin.code.success) {
						uni.showToast({
							title: '提交成功'
						})
						uni.navigateBack({})
			
					} else {
						uni.showToast({
							title: '提交失败',
							icon: 'none'
						})
					}
				}, failData => {
					console.log(failData)
					uni.showToast({
						title: '提交失败',
						icon: 'none'
			
					})
				})
			
			},
			getSubmitStageConfig() {
				
				var that = this;
				var param = {
					id: this.statgeId
				}

				this.$pin.request('GET', '/stage_config', param, successData => {
					console.log(successData)
					if (successData.code == this.$pin.code.success) {
						if(successData.data.length>0){
							var obj = successData.data[0];
							that.has_order_stage = obj.has_order_stage;
							that.has_receive_stage = obj.has_receive_stage;
							that.has_comment_stage = obj.has_comment_stage;
						}
					}
				}, failData => {
					console.log(failData)
				})

			},


			uploadBigSuccess1(e) {
				var that = this;
				console.log("uploadBigSuccess1: " + e);
				this.order_data = e[0];

			},
			uploadBigSuccess2(e) {
				var that = this;
				console.log("uploadBigSuccess2" + e);
				this.receive_data = e[0];


			},
			uploadBigSuccess3(e) {
				var that = this;
				console.log("uploadBigSuccess3" + e);
				this.comment_data = e[0];

			}
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		height: 100%;
		background: #ededed;
	}

	.container {
		padding: 20rpx;
		box-sizing: border-box;


		.product-list {
			width: 100%;
			// padding: 0 2% 3vw 2%;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.product {
				padding: 20rpx;
				box-sizing: border-box;
				width: 100%;
				background-color: #fff;
				margin: 0 0 15upx 0;
				border-radius: $pin-border-radius;
				box-shadow: $pin-shadow;
				// height: 499rpx;
			}
		}
	}

	.s-add-list-btn-icon {
		font-size: 80rpx;
		height: 80rpx;
		line-height: 80rpx;
		margin-bottom: 20rpx;
		color: #999;
	}
</style>